var tzAdminBlog = {
	save:function(obj){
		var id = $("body").data("opid");
		var title=$("#title").val();
		var description=$("#description").val();
		var categoryId=$("#categoryId").val();
		var img=$("#img").data("img");
		var musiclink=$("#musiclink").val();
		var musictor=$("#musictor").val();
		var musictitle=$("#musictitle").val();
		var musicsize=$("#musicsize").val();
		var musictime=$("#musictime").val();
		var method = "save";
		var params = {
			title:title,		
			description:description,		
			categoryId:categoryId,		
			img:img,		
			musiclink:musiclink,	
			musictor:musictor,		
			musicsize:musicsize,		
			musictitle:musictitle,		
			musictime:musictime	
		};
		if(id){
			params["id"] = id;	
			method = "update";
		}
		$.ajax({
			type:"post",
			url:basePath+"/admin/"+method+".do",
			data:params,
			success:function(data){
				if(data=="success"){
					tzMessage.tip(method=="save"?"保存成功!!!":"更新成功");
					setTimeout(function(){
						window.location.href = basePath+"/admin/index.do";
					},1000);
				}else{
					tzMessage.tip("操作失败!!!");
				}
			}
		});
	}
};

function tz_uploadsuccess(to,jdata){
	if(jdata.target=="#img"){
		$(jdata.target).data("img",jdata.url).attr("src",basePath+"/"+jdata.url+"?"+new Date().getTime());
	}else if(jdata.target=="#audio"){
		$(jdata.target).attr("src",basePath+"/"+jdata.url).data("link",jdata.url);
		$("#musicsize").val(jdata.size);
		$("#musictitle").val(jdata.name);
		$("#musiclink").val(jdata.url);
		//音乐时长的获取及处理
		audioDom.oncanplaythrough = function(){
			var time = this.duration;
			var m = Math.ceil(time / 60);
			var s = Math.ceil(time % 60);
			if(m<10) m = "0"+m;
			if(s<10) s = "0"+s;
			$("#musictime").val(m+":"+s);
		};
	}
};
/****播放暂停的设置*****/
var audioDom = document.getElementById("audio");
function playMusic(obj){
	var $i = $(obj).find("i");
	if($i.hasClass("icon-play")){
		$(obj).find("i").removeClass("icon-play").addClass("icon-pause");
		audioDom.play();
	}else{
		$(obj).find("i").removeClass("icon-pause").addClass("icon-play");
		audioDom.pause();
	}
};
